package party.damao.issue.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import party.damao.issue.service.FileService;

@RestController
@RequestMapping("/api/file")
public class FileController {
    @Autowired
    private FileService service;

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public Object upload(@RequestParam(value = "file") MultipartFile[] files) throws Exception {
        return service.upload(files);
    }

    @RequestMapping(value = "/download/{id}", name = "下载文件&正常图")
    @ResponseStatus(HttpStatus.OK)
    public void download(@PathVariable("id") String id) throws Exception {
        service.download(id);
    }

    @RequestMapping(value = "/{id}", name = "根据文件id删除文件", method = RequestMethod.DELETE)
    public void delete(@PathVariable("id") String id) throws Exception {
        service.delete(id);
    }
}
